#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTextEdit>
#include <QLineEdit>
#include <QPushButton>
#include <QListWidget>
#include <QNetworkAccessManager>
#include <QJsonObject>
#include <QDateTime>
#include <QScrollArea>
#include <QScrollBar>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class AIClient;
class HistoryManager;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void onSendClicked();
    void onAnswerReceived(const QString &answer);
    void onNetworkError(const QString &error);
    void onHistoryItemClicked(QListWidgetItem *item);
    void onClearHistoryClicked();
    void onSettingsClicked();
    void onCopyAnswerClicked();
    void onExportHistoryClicked();

private:
    Ui::MainWindow *ui;
    AIClient *m_aiClient;
    HistoryManager *m_historyManager;
    QString m_currentConversationId;

    // UI组件
    QTextEdit *m_chatDisplay;
    QLineEdit *m_inputEdit;
    QPushButton *m_sendBtn;
    QListWidget *m_historyList;
    QPushButton *m_clearHistoryBtn;
    QPushButton *m_settingsBtn;
    QPushButton *m_copyBtn;
    QPushButton *m_exportBtn;

    void setupUI();
    void appendMessage(const QString &text, bool isUser = false);
    void loadHistoryList();
    void showConversation(const QString &convId);
    QString getCurrentTimeString();
};
#endif // MAINWINDOW_H
